package mathive.server.persistant;

import java.util.Date;

import com.google.appengine.api.datastore.Key;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User {
	public static final int USER = 0;
	public static final int TEST_USER = 1;
	public static final int ADMIN = 2;
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	
	@Persistent
    private int usertype;
    
    @Persistent
    private String username;

    @Persistent
    private String hashPassword;
    
    @Persistent
    private String email;
    
    @Persistent
    private int totalScore;
    
    @Persistent
    private Date created;
    
    @Persistent
    private Date lastLogin;

    public User(String username, String hashPassword, String email) {
    	this.username = username;
    	this.hashPassword = hashPassword;
    	this.email = email;
    	usertype = USER;
    }
    
    public User(String username, String hashPassword, String email, int usertype) {
    	this.username = username;
    	this.hashPassword = hashPassword;
    	this.email = email;
    	this.usertype = usertype;
    }
    
    public Key getKey() {
        return key;
    }
    
    public int getUsertype() {
        return usertype;
    }
    
    public void setUsertype(int usertype) {
        this.usertype = usertype;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
    	this.username = username;
    }
    
    public String getHashPassword() {
        return hashPassword;
    }
    
    public void setHashPassword(String hashPassword) {
    	this.hashPassword = hashPassword;
    }
    
    public String getEmail() {
        return email;
    }
    
    public int getScore() {
    	return totalScore;
    }
    
    public void setScore(int score) {
    	totalScore = score;
    }
    
    public void addScore(int score) {
    	totalScore += score;
    }
}